import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import './assets/global.less'
import axios from 'axios'
// 引入vue-quill-editor
import VueQuillEditor from 'vue-quill-editor'
// 引入quill的样式
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
Vue.use(VueQuillEditor)
axios.defaults.baseURL = 'http://www.liulongbin.top:3008'
// 添加请求拦截器
axios.interceptors.request.use(
  config => {
    config.headers.Authorization = store.state.user.token
    return config
  },
  err => {
    return Promise.reject(err)
  }
)
// 添加响应拦截器
axios.interceptors.response.use(function (response) {
  // 对响应数据做点什么
  return response
}, function (error) {
  // 对响应错误做点什么
  if (error.response.status === 401) {
    // 清空token
    store.commit('user/updateToken', '')
    router.push('/login')
    // 提醒用户
    Vue.prototype.$message.error(error.response.data.messgae)
  }
  return Promise.reject(error)
})
// 如果需要给原型上添加成员，必须在创建对象之前
// 将axios挂载到vue原型上
Vue.prototype.$http = axios
Vue.use(ElementUI)
Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
